package com.zxw.files;

import io.minio.GetPresignedObjectUrlArgs;
import io.minio.MinioClient;
import io.minio.errors.MinioException;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @projectName: erp-cloud
 * @package: com.zxw.files
 * @className: Test
 * @author: zhangxuewei
 * @description: TODO
 * @date: 2023/8/3 10:32
 * @version: 1.0
 */
public class Test {

    public static void main(String[] args) {
        // 使用MinIO服务的端点、凭证等信息进行初始化
        String endpoint = "http://play.min.io";
        String accessKey = "YOUR-ACCESSKEYID";
        String secretKey = "YOUR-SECRETACCESSKEY";

        try {
            // 创建MinioClient对象
            MinioClient minioClient =  MinioClient.builder().endpoint(endpoint).credentials(accessKey,secretKey).build();

            // 设置要获取预签名URL的对象信息
            String bucketName = "your-bucket";
            String objectName = "your-object";
            int expiryInSeconds = 3600; // URL过期时间，以秒为单位

            // 获取预签名URL
            String presignedUrl = minioClient.getPresignedObjectUrl(new GetPresignedObjectUrlArgs());

            // 打印预签名URL
            System.out.println("Presigned URL: " + presignedUrl);
        } catch (MinioException e) {
            System.out.println("Error occurred: " + e);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
    }
}
